<?php
/**
 * Created by PhpStorm.
 * User: bigniu
 * Date: 2019-12-17
 * Time: 15:30:59
 */

namespace app\admin\controller;


use think\Controller;

/**
 * TODO 待注释
 * Class VipShop
 * @package app\admin\controller
 */
class ShopsType extends Admin
{
  public function getList(){
      $page = input("page/i", 1) <= 1 ? 1 : input("page/i", 1);
      $pageSize = input("pageSize/i", 10) <= 10 ? 10 : input("pageSize/i", 10);
      $list = Db("shop_type")->page($page, $pageSize)->select();
      $count = Db("shop_type")->count();
      return success("获取成功", $list, $page, $count);
  }
  public function add(){
      $title = input("name");
      $icon = input("icon");
      $sort_id = input("sort_id");
      $pid = input("pid");
      $data = [
          'name'=>$title,
          'icon'=>$icon,
          'sort_id'=>$sort_id,
          'level'=>1,
          'pid'=>$pid,
          'enable'=>1,
          'create_time'=>TIME
      ];
      $res = Db("shop_type")->insert($data);
      if($res){
          return success("添加成功");
      }
      return error("添加失败");
  }
  public function delete(){
      $ids = input('ids/a');
      u_log("删除VIP商品(".implode($ids,',')."成功");
      Db("shop_type")->whereIn('id', $ids)->delete();
      return success("删除成功");
  }
  public function update(){
      $id = input("id/i");
      $title = input("name");
      $icon = input("icon");
      $sort_id = input("sort_id");
      $pid = input("pid");
      $enable = input("enable",1);
      $data = [
          'name'=>$title,
          'icon'=>$icon,
          'sort_id'=>$sort_id,
          'level'=>1,
          'pid'=>$pid,
          'enable'=>$enable,
          'create_time'=>TIME
      ];
      $res = Db("shop_type")->where(['id'=>$id])->update($data);
      if($res){
          return success("修改成功");
      }
      return error("修改失败");
  }
}
